package com.woniu.controller;

import com.woniu.entity.Unit;
import com.woniu.service.UnitService;
import com.woniu.util.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/unit")
public class UnitController {
    @Resource
    private UnitService unitService;
    @GetMapping("/findAll")
    public ResponseUtil findAll(){
        return unitService.findAll();
    }

    @GetMapping("findByUnitId/{unitId}")
    public ResponseUtil findByUnitId(@PathVariable Integer unitId) {
        return unitService.findByUnitId(unitId);
    }

    @GetMapping("findByName/{unitName}")
    public ResponseUtil findByName(@PathVariable String unitName) {
        return unitService.findByName(unitName);
    }
    @PostMapping("/add")
    public ResponseUtil add(@RequestBody Unit unit){
        return unitService.add(unit);
    }
    @PutMapping("/update")
    public ResponseUtil update(@RequestBody Unit unit){
        return unitService.update(unit);
    }
    @DeleteMapping("/delete/{unitId}")
    public ResponseUtil delete(@PathVariable Integer unitId){
        return unitService.delete(unitId);
    }
}

